﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MarvellousWorks.PracticalPatternNet8.Concept.Iterating;

public class RawIterator
{
    private int[] data = new int[] { 0,1, 2, 3, 4, 5, 6, 7, 8, 9 };

    /// <summary>
    /// 最简单的基于数组的全部遍历
    /// </summary>
    /// <returns></returns>
    public IEnumerator<int> GetEnumerator()
    {
        foreach (var item in data)
            yield return item;
    }

    /// <summary>
    /// 返回某个区间内数据的 IEnumerable
    /// </summary>
    /// <param name="start"></param>
    /// <param name="end"></param>
    /// <returns></returns>
    public IEnumerable<int> GetRange(int start, int end)
    {
        for (int i = start; i < end; i++)
        {
            yield return data[i];
        }
    }


    public IEnumerable<string> GetNames()
    {
        yield return "hello";
        yield return "world";
        yield return "!";
    }

}
